const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
  return sequelize.define('cors', {
    id: {
      autoIncrement: true,
      type: DataTypes.INTEGER,
      allowNull: false,
      primaryKey: true
    },
    name: {
      type: DataTypes.STRING(255),
      allowNull: true
    },
    username: {
      type: DataTypes.STRING(50),
      allowNull: true,
      unique: "username_l"
    },
    passowrd: {
      type: DataTypes.STRING(255),
      allowNull: true
    },
    online: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: "在线"
    },
    port: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: "端口"
    },
    last_request: {
      type: DataTypes.DATE,
      allowNull: true,
      comment: "最近请求时间"
    },
    create_at: {
      type: DataTypes.DATE,
      allowNull: true,
      defaultValue: Sequelize.Sequelize.literal('CURRENT_TIMESTAMP')
    }
  }, {
    sequelize,
    tableName: 'cors',
    timestamps: true,
    indexes: [
      {
        name: "PRIMARY",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "id" },
        ]
      },
      {
        name: "username_l",
        unique: true,
        using: "BTREE",
        fields: [
          { name: "username" },
        ]
      },
    ]
  });
};
